{*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <contact@prestashop.com>
*  @copyright  2007-2012 PrestaShop SA
*  @version  Release: $Revision: 6594 $
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*}
{if ($content_only == 0)}
	{include file="$tpl_dir./breadcrumb.tpl"}
{/if}
{if isset($cms) && !isset($category)}
	{if !$cms->active}
		<br />
		<div id="admin-action-cms">
			<p>{l s='This CMS page is not visible to your customers.'}
			<input type="hidden" id="admin-action-cms-id" value="{$cms->id}" />
			<input type="submit" value="{l s='Publish'}" class="exclusive" onclick="submitPublishCMS('{$base_dir}{$smarty.get.ad|escape:'htmlall':'UTF-8'}', 0, '{$smarty.get.adtoken|escape:'htmlall':'UTF-8'}')"/>
			<input type="submit" value="{l s='Back'}" class="exclusive" onclick="submitPublishCMS('{$base_dir}{$smarty.get.ad|escape:'htmlall':'UTF-8'}', 1, '{$smarty.get.adtoken|escape:'htmlall':'UTF-8'}')"/>
			</p>
			<div class="clear" ></div>
			<p id="admin-action-result"></p>
			</p>
		</div>
	{/if}
	<div class="rtitle">{$cms->meta_title}</div>
	<div class="rte{if $content_only} content_only{/if}">
		{$cms->content}
	</div>
{elseif isset($category)}
	<div class="block-cms">
		<h1><a href="{if $category->id eq 1}{$base_dir}{else}{$link->getCMSCategoryLink($category->id, $category->link_rewrite)}{/if}">{$category->name|escape:'htmlall':'UTF-8'}</a></h1>
		{if isset($sub_category) & !empty($sub_category)}	
			<h4>{l s='List of sub categories in %s:' sprintf=$category->name}</h4>
			<ul class="bullet">
				{foreach from=$sub_category item=subcategory}
					<li>
						<a href="{$link->getCMSCategoryLink($subcategory.id_cms_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}">{$subcategory.name|escape:'htmlall':'UTF-8'}</a>
					</li>
				{/foreach}
			</ul>
		{/if}
		{if isset($cms_pages) & !empty($cms_pages)}
		<h4>{l s='List of pages in %s:' sprintf=$category->name}</h4>
		
			<ul class="cms-items bullet">
				{assign "actualCount" 1}
				{foreach from=$cms_pages item=cmspages}
					{if isset($cmspages.id_cms) and isset($cmspages.isShow) and $actualCount++}
					<li>
						<a class="cms-avatar" href="{$link->getCMSLink($cmspages.id_cms, $cmspages.link_rewrite)|escape:'htmlall':'UTF-8'}">{$cmspages.avatar}</a>
						<span class="cms-title"><a href="{$link->getCMSLink($cmspages.id_cms, $cmspages.link_rewrite)|escape:'htmlall':'UTF-8'}">{$cmspages.meta_title|escape:'htmlall':'UTF-8'}</a></span>
						<!--span class="cms-desc">{$cmspages.short_content|escape:'htmlall':'UTF-8'}</span-->
						<span class="cms-desc">{$cmspages.short_content}</span>
						<a class="cms-read-more" href="{$link->getCMSLink($cmspages.id_cms, $cmspages.link_rewrite)|escape:'htmlall':'UTF-8'}">Xem tiếp</a>
					</li>
					{/if}
				{/foreach}
			</ul>
			
		{/if}
	</div>
{else}
	{l s='This page does not exist.'}
{/if}
<br />
<div style="clear:both"></div>
{if isset($cms_pages) and $cms_pages.total_pages > 1}
<div class="pagination-wrap">
		<ul class="pagination-list">
		
			{if !empty($cms_pages) and isset($cms_pages.total_pages)}
				{if $cms_pages.total_pages > 1 and $cms_pages.current_page > 3}
					<li class="go-first"><a href="{$link->getCMSCategoryLink($category->id, $category->link_rewrite)}">&lt;&lt;</a></li>
				{/if}
				{assign "isHaveBack" 0}
				{assign "isHaveNext" 0}
				{for $i=0 to $cms_pages.total_pages }
					{if $isHaveBack == 0 and $i+3 < $cms_pages.current_page }
						{assign "isHaveBack" 1}
						<li class="go-back"><a href="{$link->getCMSCategoryLink($category->id, $category->link_rewrite)}&p={$cms_pages.current_page-3}">...</a></li>
					{/if}
					
					{if $i+3 >= $cms_pages.current_page and $i-2 < $cms_pages.current_page and $i < $cms_pages.total_pages}
						<li class="{if $i+1 == $cms_pages.current_page }active{/if}"><a href="{$link->getCMSCategoryLink($category->id, $category->link_rewrite)}&p={$i+1}">{$i+1}</a></li>
					{/if}
					
					{if $isHaveNext == 0 and $i-2 > $cms_pages.current_page }
						{assign "isHaveNext" 1}
						<li class="go-next"><a href="{$link->getCMSCategoryLink($category->id, $category->link_rewrite)}&p={$cms_pages.current_page+3}">...</a></li>
					{/if}	
				{/for}
			{/if}
			{if $cms_pages.total_pages > 1 and $cms_pages.current_page+2<$cms_pages.total_pages}
				<li class="go-last"><a href="{$link->getCMSCategoryLink($category->id, $category->link_rewrite)}&p={$cms_pages.total_pages}">&gt;&gt;</a></li>
			{/if}
		</ul>
		<span class="pagination-text">Bài {$cms_pages.start_item+1} - {$cms_pages.start_item+$actualCount-1} trên tổng số {$cms_pages.total_items} bài</span>
</div>
{/if}
<div style="clear:both;"></div>
{if isset($cms) and isset($cms->related_pages) & !empty($cms->related_pages)}

	<div class="related_cms">
		<span class="related-title">Các bài viết liên quan</span>
			<ul class="cms-items bullet">
				{assign "actualCount" 1}
				{foreach from=$cms->related_pages item=cmspages}
					{if isset($cmspages.id_cms) and $cmspages.id_cms != $cms->id and $actualCount++ < 11}
					<li>
						<span class="ordinal">{$actualCount-1}.</span>
						<!--a class="cms-avatar" href="{$link->getCMSLink($cmspages.id_cms, $cmspages.link_rewrite)|escape:'htmlall':'UTF-8'}">{$cmspages.avatar}</a-->
						<span class="cms-title"><a href="{$link->getCMSLink($cmspages.id_cms, $cmspages.link_rewrite)|escape:'htmlall':'UTF-8'}">{$cmspages.meta_title|escape:'htmlall':'UTF-8'}</a></span>
						<!--span class="cms-desc">{$cmspages.short_content}</span-->
						<!--a class="cms-read-more" href="{$link->getCMSLink($cmspages.id_cms, $cmspages.link_rewrite)|escape:'htmlall':'UTF-8'}">Xem tiếp</a-->
					</li>
					{/if}
				{/foreach}
			</ul>
	</div>
	
{/if}


			<style>
				.rtitle {
					margin: 15px 0 0 15px;
					color: darkred;
					font-weight: bold;
					font-size: 150%;
				}
			
				.cms-items {
					margin-left: 10px;
					margin-right: 10px;
				}
				.cms-items li {
					position: relative;
					float: left;
					color: #555;
					font-size: 12px;
					line-height: 1.5;
					width: 100%;
					border-top: 1px dotted lightgrey;
					padding-top: 10px;
					margin-bottom: 10px;
				}
					.cms-items li .cms-avatar {
						float: left;
						max-width: 30%;
					}
					
						.cms-items li .cms-avatar img {
							width: 120px !important;
							height: 100px !important;
							padding: 4px;
							border: 1px solid #ddd;
						}
						.cms-items li .cms-avatar:hover img {
							border-color: darkred;
						}
						
					.cms-items li .cms-title, .cms-items li .cms-desc {
						float: left;
						width: 79%;
						margin-left: 10px;
						text-align: justify;
					}
						.cms-items li .cms-title a, .cms-items li .cms-read-more {
							color: darkred;
							font-weight: bold;
						}
					.cms-items li .cms-desc {
						margin-top: 5px;
						max-height: 70px;
						overflow: hidden;
					}
					.cms-items li .cms-read-more {
						position: absolute;
						bottom: 0;
						right: 5px;
					}
					
					.pagination-wrap {
						width: 100%;
						border-top: 1px dotted #ccc;
						padding-top: 10px;
					}
						.pagination-wrap .pagination-list, .pagination-wrap .pagination-text {
							float: right;
							color: black;
							font-size: 12px;
							font-weight: bold;
							margin-right: 10px;
						}
							.pagination-wrap .pagination-list li {
								display: inline-block;
								cursor: pointer;
							}
								.pagination-wrap .pagination-list li a {
									padding: 5px 10px;
									border: 1px solid darkred;
									color: black;
									font-weight: bold;
									text-decoration: none;
									background: white;
								}
								.pagination-wrap .pagination-list li.active a,
								.pagination-wrap .pagination-list li:hover a {
									color: white;
									background-color: darkred;
								}
				.related_cms {
					width: 100%;
					margin-left: 15px;
				}
					.related_cms .related-title {
						color: black;
						font-weight: bold;
						font-size: 140%;
					}
					.related_cms .ordinal {
						float: left;
						color: black;
					}
			</style>
			